/**
 * Created by no1 on 2015/7/29.
 */
'use strict';
/*
 var DaoBase = require('./DaoBase');
 var util = require("util");
 var D = require('./function');

 var debugLog = require('../../function.js').debugLog;

 function UserDao() {
 DaoBase.call();
 }
 util.inherits(UserDao, DaoBase);

 UserDao.prototype.getUserInfo123=function*(uid){
 var info = this.db.query('SELECT * FROM user WHERE uid=?',[uid]);
 console.log(info);
 return info;
 };
 */


var DaoBase = require('./DaoBase');
var D = require('./function');
let F = require('../../function');
let db = require('./models')
var util = require("util");

function UserDao(data) {
  data = data || {}
  data.model = data.model || db.user;
  DaoBase.call(this, data);
}

util.inherits(UserDao, DaoBase);
/*
 @todo 查询
 @ pipeline 条件
 @ opt 参数
 */
UserDao.prototype.findById = function*(uid, opt) {
  let ret = yield this.model.findOne({where: {uid: uid}});
  ret || (ret = {});
  if (!ret || !ret.dataValues) return F.returnData(1, '没有找到该用户', ret.dataValues);
  return F.returnData(0, '找到这个用户', ret.dataValues)
};

/*
 @todo 查询
 @ pipeline 条件
 @ opt 参数
 */
UserDao.prototype.getUserInfo = function*(uid) {
  var ret = yield this.db.query('SELECT * FROM mh_user WHERE uid=?  AND groupid !=5', [uid]);
  if (!ret || ret.length != 1) return F.returnData(1, '查询失败');
  return F.returnData(0, '查询成功', ret);
};

UserDao.prototype.gitNameByids = function *(uids) {
  let str = uids.join(',');
  let retUsers = yield this.db.query('SELECT uid, mobile FROM mh_user WHERE uid in (' + str + ') AND groupid !=5');
  return retUsers;
};


module.exports = UserDao;

